// backend/routes/api.js

const express = require('express');
const router = express.Router();

// 导入所有控制器
const roomController = require('../controllers/roomController');
const guestController = require('../controllers/guestController');
const checkinController = require('../controllers/checkinController');
const consumptionController = require('../controllers/consumptionController');
const menuController = require('../controllers/menuController');
const statsController = require('../controllers/statsController');

// --- 管理员 API 路由 ---

// 房间管理
router.post('/admin/rooms', roomController.addRoom);
router.post('/admin/rooms/import', roomController.bulkImportRooms);
router.get('/admin/rooms', roomController.getAllRooms);
router.get('/admin/rooms/available', roomController.getAvailableRooms);
router.put('/admin/rooms/:id', roomController.updateRoom);
router.delete('/admin/rooms/:id', roomController.deleteRoom);

// 客户管理
router.post('/admin/guests', guestController.addGuest);
router.get('/admin/guests', guestController.searchGuests);
router.put('/admin/guests/:id', guestController.updateGuest);
router.delete('/admin/guests/:id', guestController.deleteGuest);

// 入住管理
router.post('/admin/checkins', checkinController.createCheckin);
// 退房路由：PUT 请求到 /admin/checkins/:id/checkout
router.put('/admin/checkins/:id/checkout', checkinController.checkout);
router.get('/admin/checkins', checkinController.getAllCheckins);
router.get('/admin/checkins/active', checkinController.getActiveCheckins);
router.get('/admin/checkins/:id', checkinController.getCheckinById); // 获取单个入住详情

// 消费管理 (管理员)
router.post('/admin/consumptions', consumptionController.addConsumption); // 添加消费
router.get('/admin/consumptions/:checkinId', consumptionController.getConsumptionsByCheckin); // 查看某个入住的消费明细
router.delete('/admin/consumptions/:id', consumptionController.deleteConsumption); // 删除消费记录

// 商品管理 (管理员)
router.get('/admin/menuitems', menuController.getAllMenuItems);
router.post('/admin/menuitems', menuController.addMenuItem);
router.put('/admin/menuitems/:id', menuController.updateMenuItem);
router.delete('/admin/menuitems/:id', menuController.deleteMenuItem);
router.post('/admin/menuitems/import', menuController.bulkImportMenuItems); // 批量导入菜单项

// 统计与仪表盘
router.get('/admin/stats/rooms', statsController.getRoomStats);
router.get('/admin/stats/consumptions', statsController.getConsumptionStats);
router.get('/admin/dashboard/overview', statsController.getDashboardOverview);

// --- 客户端 API 路由 ---
router.get('/client/guests/:idCard', guestController.getGuestByCard);
router.get('/client/checkins/:idCard', checkinController.getCheckinsByGuestCard);
// 客户端查询自己的消费记录 (基于入住ID)
router.get('/client/consumptions/:checkinId', consumptionController.getConsumptionsByCheckin); // 客户端查看消费 (复用管理员接口)
// 客户端添加消费的路由 (如果需要客户端直接添加消费的入口)
router.post('/client/checkins/:checkinId/consumptions', consumptionController.addConsumption);


module.exports = router;
